using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Graphics.Model;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;

using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;
#endif

using Gnome.Entities;
using FlatRedBall.Graphics;

namespace Gnome.Screens
{
	public partial class ScoreScreen
	{
		public void CustomInitialize()
        {
            //BGSprite.Alpha = 0.3f;
            for (int i = 0; i < 4; i++)
            {
                HudNumber digit = new HudNumber(ContentManagerName, true);
                digit.Position.X = 116 + i * 48f;
                digit.Position.Y = -57;
                ScoreCounter.Add(digit);
                SpriteManager.AddToLayer(digit.Number, OverlayLayer);
            }
            Trophy.Y = -200;
            Trophy.X = -260;
            WinnerDisplay.X = 156;
            WinnerDisplay.Y = -250;
            if (GlobalData.Score > GlobalData.P2Score)
            {
                WinnerDisplay.CurrentChainName = "P1Wins";
            }
            else if (GlobalData.Score < GlobalData.P2Score)
            {
                WinnerDisplay.CurrentChainName = "P2Wins";
            }
            else
            {
                WinnerDisplay.CurrentChainName = "Tie";
            }
            SpriteManager.AddToLayer(Trophy,OverlayLayer);
            SpriteManager.AddToLayer(WinnerDisplay, OverlayLayer);
            if (GlobalData.is2P)
                WinnerDisplay.Visible = true;
            else
                WinnerDisplay.Visible = false;
		}

		public void CustomActivity(bool firstTimeCalled)
		{
            if(firstTimeCalled)
            {
                if (!GlobalData.is2P || GlobalData.Score > GlobalData.P2Score)
                {
                    String scorestring = GlobalData.Score.ToString();
                    int toappend = 4 - scorestring.Length;
                    for (int i = 0; i < toappend; i++)
                    {
                        scorestring = "0" + scorestring;
                    }
                    for (int i = scorestring.Length - 1; i >= 0; i--)
                    {
                        int fuck = (int)(GlobalData.Score / ((int)Math.Pow(10, (int)(Math.Log10(GlobalData.Score) + 1) - i)) % 10);
                        //ScoreCounter[i].NumberScaleX = 21f;
                        //ScoreCounter[i].NumberScaleY = 36f;
                        switch (scorestring[i])
                        {
                            case '0':
                                ScoreCounter[i].Number.CurrentChainName = "Zero";
                                break;
                            case '1':
                                ScoreCounter[i].Number.CurrentChainName = "One";
                                break;
                            case '2':
                                ScoreCounter[i].Number.CurrentChainName = "Two";
                                break;
                            case '3':
                                ScoreCounter[i].Number.CurrentChainName = "Three";
                                break;
                            case '4':
                                ScoreCounter[i].Number.CurrentChainName = "Four";
                                break;
                            case '5':
                                ScoreCounter[i].Number.CurrentChainName = "Five";
                                break;
                            case '6':
                                ScoreCounter[i].Number.CurrentChainName = "Six";
                                break;
                            case '7':
                                ScoreCounter[i].Number.CurrentChainName = "Seven";
                                break;
                            case '8':
                                ScoreCounter[i].Number.CurrentChainName = "Eight";
                                break;
                            case '9':
                                ScoreCounter[i].Number.CurrentChainName = "Nine";
                                break;
                            default:
                                ScoreCounter[i].Number.CurrentChainName = "Zero";
                                break;
                        }
                    }

                    foreach (HudNumber number in ScoreCounter)
                    {
                        number.NumberScaleX = 21f;
                        number.NumberScaleY = 36f;
                    }

                    if (GlobalData.Score > 500 && GlobalData.Score < 1000)
                        Trophy.CurrentChainName = "Bronze";
                    else if (GlobalData.Score >= 1000 && GlobalData.Score < 2500)
                        Trophy.CurrentChainName = "Silver";
                    else if (GlobalData.Score >= 2500)
                        Trophy.CurrentChainName = "Gold";
                    else if (GlobalData.Score > 9000)
                        Trophy.CurrentChainName = "Winona";
                }
                else
                {
                    String scorestring = GlobalData.P2Score.ToString();
                    int toappend = 4 - scorestring.Length;
                    for (int i = 0; i < toappend; i++)
                    {
                        scorestring = "0" + scorestring;
                    }
                    for (int i = scorestring.Length - 1; i >= 0; i--)
                    {
                        int fuck = (int)(GlobalData.P2Score / ((int)Math.Pow(10, (int)(Math.Log10(GlobalData.P2Score) + 1) - i)) % 10);
                        //ScoreCounter[i].NumberScaleX = 21f;
                        //ScoreCounter[i].NumberScaleY = 36f;
                        switch (scorestring[i])
                        {
                            case '0':
                                ScoreCounter[i].Number.CurrentChainName = "Zero";
                                break;
                            case '1':
                                ScoreCounter[i].Number.CurrentChainName = "One";
                                break;
                            case '2':
                                ScoreCounter[i].Number.CurrentChainName = "Two";
                                break;
                            case '3':
                                ScoreCounter[i].Number.CurrentChainName = "Three";
                                break;
                            case '4':
                                ScoreCounter[i].Number.CurrentChainName = "Four";
                                break;
                            case '5':
                                ScoreCounter[i].Number.CurrentChainName = "Five";
                                break;
                            case '6':
                                ScoreCounter[i].Number.CurrentChainName = "Six";
                                break;
                            case '7':
                                ScoreCounter[i].Number.CurrentChainName = "Seven";
                                break;
                            case '8':
                                ScoreCounter[i].Number.CurrentChainName = "Eight";
                                break;
                            case '9':
                                ScoreCounter[i].Number.CurrentChainName = "Nine";
                                break;
                            default:
                                ScoreCounter[i].Number.CurrentChainName = "Zero";
                                break;
                        }
                    }
                    foreach (HudNumber number in ScoreCounter)
                    {
                        number.NumberScaleX = 21f;
                        number.NumberScaleY = 36f;
                    }

                    if (GlobalData.P2Score > 500 && GlobalData.P2Score < 1000)
                        Trophy.CurrentChainName = "Bronze";
                    else if (GlobalData.P2Score >= 1000 && GlobalData.P2Score < 2500)
                        Trophy.CurrentChainName = "Silver";
                    else if (GlobalData.P2Score >= 2500)
                        Trophy.CurrentChainName = "Gold";
                    else if (GlobalData.P2Score > 9000)
                        Trophy.CurrentChainName = "Winona";
                }
            }
		}

		public void CustomDestroy()
		{


		}

        private static void CustomLoadStaticContent(string contentManagerName)
        {


        }

	}
}
